<?php

namespace app\admin\service;
use app\admin\model\Menu;
use think\facade\Db;

class MenuService
{   

    public function getMenuList()
    {
        $menus = Menu::field('id,parent_id,type,title,url,node,display,status,create_time,update_time')->select();
        $data = $menus->isEmpty() ? [] : generateTreeOption($menus->toArray(),'title');

        return $data;
    }

    public function findMenu($id)
    {
        $menu = Db::name('menu')->withOutField('create_time,update_time')->find($id);

        return $menu;
    }


    public function getMenuOption()
    {
        $menus = Db::name('menu')->field('id,parent_id,title')->select();
        $data = $menus->isEmpty() ? [] : generateTreeOption($menus->toArray(),'title');

        return $data;
    }
    

    public function deleteMenu($id)
    {   
        $model = new Menu();
        $res =$model->where('id',$id)->delete();
       
        return $res ? true : false;
    }
}